package com.cskaoyan.config;

import com.cskaoyan.filter.FirstFilter;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

/**
 * @author stone
 * @date 2022/09/01 15:51
 */
public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfiguration.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{MvcConfiguration.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    @Override
    protected Filter[] getServletFilters() {
        FirstFilter firstFilter = new FirstFilter();
        // 提供字符集值，要求doFilterInternal执行过程中的判断条件为true
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter("utf-8", true);
        return new Filter[]{firstFilter,characterEncodingFilter};
    }
}
